package com.yin.myproject.zk.WatcherSample;

import com.yin.myproject.zk.client.ZkClient;
import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Eason on 2017/8/7.
 */
public class WatcherClient1 implements Runnable {

    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.execute(new WatcherClient1());
    }

    @Override
    public void run() {
        CuratorFramework zkClient = ZkClient.getNewZkClient();
        zkClient.start();
        try {
            zkClient.getData().usingWatcher(new Watcher() {
                @Override
                public void process(WatchedEvent event) {
                    System.out.println("***********************************");
                    System.out.println("WatchedEvent path-->" + event.getPath());
                    System.out.println("WatchedEvent type" + event.getType().toString());
                }
            }).forPath("/task/node/192.168.0.1");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
